package site.zhouinfo.findpath;

/**
 * 节点
 *
 * @author zhou
 * @create 2017-10-24 10:50
 * @email zhouinfo@qq.com
 * @blog blog.zhouinfo.site
 */
public class NodePoint implements Comparable<NodePoint> {

    private NodePoint parentNode;
    private int F;
    private int G;
    private int H;

    private int x, y;

    public NodePoint() {
    }

    public NodePoint(int x, int y) {
        this.x = x;
        this.y = y;
    }

    public void clacF() {
        this.F = this.G + this.H + 1;
    }

    public NodePoint getParentNode() {
        return parentNode;
    }

    public void setParentNode(NodePoint parentNode) {
        this.parentNode = parentNode;
    }

    public int getF() {
        return F;
    }

    public void setF(int f) {
        F = f;
    }

    public int getG() {
        return G;
    }

    public void setG(int g) {
        G = g;
    }

    public int getH() {
        return H;
    }

    public void setH(int h) {
        H = h;
    }

    public int getX() {
        return x;
    }

    public void setX(int x) {
        this.x = x;
    }

    public int getY() {
        return y;
    }

    public void setY(int y) {
        this.y = y;
    }

    @Override
    public int compareTo(NodePoint n) {
        return this.F - n.F;
    }

    @Override
    public String toString() {
        final StringBuilder sb = new StringBuilder("{");
        sb.append("(").append(x);
        sb.append(",").append(y);
        sb.append("), \t").append(F);
        sb.append(" = ").append(G);
        sb.append(" + ").append(H);
        sb.append('}');
        return sb.toString();
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (!(o instanceof NodePoint)) {
            return false;
        }

        NodePoint nodePoint = (NodePoint) o;

        return x == nodePoint.x && y == nodePoint.y;
    }

    @Override
    public int hashCode() {
        int result = x;
        result = 31 * result + y;
        return result;
    }
}
